<html>
<head><meta charset="utf-8"><title>anon const parent · project-const-generics · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/index.html">project-const-generics</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/anon.20const.20parent.html">anon const parent</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="246554323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/anon%20const%20parent/near/246554323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/anon.20const.20parent.html#246554323">(Jul 20 2021 at 07:43)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![feature(const_generics, const_evaluatable_checked)]</span><span class="w"></span>
<span class="cp">#![allow(incomplete_features, unused)]</span><span class="w"></span>
<span class="cp">#![crate_type = </span><span class="s">"lib"</span><span class="cp">]</span><span class="w"></span>

<span class="k">fn</span> <span class="nf">foo</span><span class="o">&lt;</span><span class="k">const</span><span class="w"> </span><span class="n">N</span>: <span class="kt">usize</span><span class="o">&gt;</span><span class="p">()</span><span class="w"> </span><span class="k">where</span><span class="w"> </span><span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">]</span>: <span class="nb">Sized</span> <span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">x</span>: <span class="p">[</span><span class="kt">u8</span><span class="p">;</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="kd">let</span><span class="w"> </span><span class="n">y</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[</span><span class="mi">0</span><span class="p">;</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="mi">1</span><span class="p">];</span><span class="w"></span>
<span class="w">        </span><span class="n">y</span><span class="p">.</span><span class="n">len</span><span class="p">()</span><span class="w"></span>
<span class="w">    </span><span class="p">}];</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>
<p>here <code>let y = [0; N + 1];</code> has <code>ty::Generics</code> with <code>parent</code> being <code>foo</code>. I would prefer <code>parent</code> to be the <code>x</code> anon const instead so that the predicate filtering does not have to look inside of anonymous constants.</p>
<p>Is the reason for the current state just for perf or is there a more complex reason?</p>



<a name="246565183"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/anon%20const%20parent/near/246565183" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/anon.20const.20parent.html#246565183">(Jul 20 2021 at 10:00)</a>:</h4>
<p>probably an accident</p>



<a name="246565240"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/anon%20const%20parent/near/246565240" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/anon.20const.20parent.html#246565240">(Jul 20 2021 at 10:00)</a>:</h4>
<p>since we never had generics in constants before, no one noticed</p>



<a name="246565292"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/anon%20const%20parent/near/246565292" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/anon.20const.20parent.html#246565292">(Jul 20 2021 at 10:00)</a>:</h4>
<p>maybe check how closures work?</p>



<a name="246565310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/anon%20const%20parent/near/246565310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/anon.20const.20parent.html#246565310">(Jul 20 2021 at 10:00)</a>:</h4>
<p>if nested closures always point to their main parent, that's probably why</p>



<a name="246565348"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/260443-project-const-generics/topic/anon%20const%20parent/near/246565348" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/260443-project-const-generics/topic/anon.20const.20parent.html#246565348">(Jul 20 2021 at 10:01)</a>:</h4>
<p>but even then, it seems reasonable to make them a real tree instead of flattening the parents to the function</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>